package cn.wsalix.web.servlet;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;

import javax.servlet.http.HttpServlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.wsalix.web.task.ChatTask;
import cn.wsalix.web.task.TempTask;


/**
 * Created with IntelliJ IDEA. User: long Date: 13-4-25 Time: 下午6:39
 */
public class InitServlet extends HttpServlet {
	protected static Logger logger = LoggerFactory.getLogger(InitServlet.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = -2836039754973185174L;

	static {
		try {
			logger.info("启动定时器=====>");
			Timer timer = new Timer();
			timer.schedule(new ChatTask(),5*60*1000,10*60*1000);//在8分钟后执行此任务,每次间隔30分钟
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void init() {
		logger.info("启动定时器=====>");
		Timer tempTimer = new Timer();
		tempTimer.schedule(new TempTask(),20*60*1000,60*60*1000);//20分钟后执行此任务,每隔1小时执行一次

	}

	// 增加或减少天数
	public Date addDay(Date date, int num) {
		Calendar startDT = Calendar.getInstance();
		startDT.setTime(date);
		startDT.add(Calendar.DAY_OF_MONTH, num);
		return startDT.getTime();
	}
}
